package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IRegionService regionService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery qo){
        Page<Destination> page = destinationService.query(qo);
        model.addAttribute("page",page );
        System.out.println(qo.getParentId());
        model.addAttribute("toasts",destinationService.getToasts(qo.getParentId()));
        return "/destination/list";
    }

    @RequestMapping("/updateInfo")
    @ResponseBody
    public JsonResult updateInfo(String id , String info){
        destinationService.updateInfo(id,info);
        return new JsonResult(true,"");
    }
}
